#! python3
# lucky.py - Opens several Google search results.
import requests, sys, webbrowser, bs4 , pprint

print('5 Tabs...')
res = requests.get('http://www.baidu.com/baidu?wd=' + ' '.join(sys.argv[1:]))
res.raise_for_status()

# Retrieve top search result links.
soup = bs4.BeautifulSoup(res.text, "html.parser")
# Open a browser tab for each result.
linkElems = soup.select('.c-container h3 a')
numOpen = min(5, len(linkElems))
for i in range(numOpen):
    webbrowser.open(str(linkElems[i].get('href')))
